/*
 * compiler/ints.hh - Integer types of fixed sizes.
 * Copyright (C) 2007  Mikhail Vorozhtsov
 * See the LICENSE section of the README file for details.
 */

/* $Id$ */

#ifndef HEADER_LIBCOMPILER_COMPILER_INTS_HH
#define HEADER_LIBCOMPILER_COMPILER_INTS_HH

template <unsigned int BITS>
class int_t;

#define __BUILD_INT(TYPE) \
  template <> \
  class int_t<sizeof (TYPE) * 8> \
  { \
  public: \
    typedef TYPE type_t; \
    typedef signed TYPE signed_type_t; \
    typedef unsigned TYPE unsigned_type_t; \
  };

#define __BUILD_NEW_INT(TYPE,PREV,FAKE) \
  template <> \
  class int_t<(sizeof (TYPE) == sizeof (PREV)) ? FAKE : sizeof (TYPE) * 8> \
  { \
  public: \
    typedef TYPE type_t; \
    typedef signed TYPE signed_type_t; \
    typedef unsigned TYPE unsigned_type_t; \
  };

__BUILD_INT (char)
__BUILD_NEW_INT (short, char, 0)
__BUILD_NEW_INT (int, short, 1)
__BUILD_NEW_INT (long, int, 2)
__BUILD_NEW_INT (long long, long, 3)

#undef __BUILD_INT

typedef int_t<8>::signed_type_t i8_t;
typedef int_t<8>::unsigned_type_t u8_t;
typedef int_t<16>::signed_type_t i16_t;
typedef int_t<16>::unsigned_type_t u16_t;
typedef int_t<32>::signed_type_t i32_t;
typedef int_t<32>::unsigned_type_t u32_t;
typedef int_t<64>::signed_type_t i64_t;
typedef int_t<64>::unsigned_type_t u64_t;

#ifdef IN_32BIT_CODE
typedef u32_t word_t;
#else
typedef u64_t word_t;
#endif

#define U64(x) ((u64_t) x ## ULL)

#endif /* HEADER_LIBCOMPILER_COMPILER_INTS_HH */

